<template>
  <el-dialog title="检定记录" width="1170px" :visible.sync="dialogTableVisible">
    <el-table :data="recordList" height="400" size="small" v-loading="loading">
      <el-table-column type="index" label="No" :index="indexMethod"></el-table-column>
      <el-table-column prop="verificationTime" label="检定时间">
        <template slot-scope="scope">
          {{ scope.row.verificationTime | changeDate }}
        </template>
      </el-table-column>
      <el-table-column prop="verificationUnit" label="检定单位"></el-table-column>
      <el-table-column prop="verificationResult" label="检定结果"></el-table-column>
      <el-table-column prop="certificateCode" label="证书编码"></el-table-column>
      <el-table-column prop="opinion" label="检定意见"></el-table-column>
      <el-table-column prop="nextVerificationTime" label="下次检定时间">
        <template slot-scope="scope">
          {{ scope.row.nextVerificationTime | changeDate }}
        </template>
      </el-table-column>
      <el-table-column prop="registrant" label="登记人"></el-table-column>
      <el-table-column prop="registrationTime" label="登记时间">
        <template slot-scope="scope">
          {{ scope.row.registrationTime | changeDate }}
        </template>
      </el-table-column>
    </el-table>

    <Pagination :pageData="pageData" @pageNum="pageNumData" @pageSize="pageSizeData"></Pagination>
  </el-dialog>
</template>

<script>
import Pagination from "@/components/Pagination";
import HttpInterface from '../../util/httpInterface';

export default {
  name: "TestRecordModal",
  components: {
    Pagination
  },
  data() {
    return {
      pageData: {
        total: 0,
        pageNum: 1,
        pageSize: 20
      },
      dialogTableVisible: false,
      recordList: [],
      loading: false,
      checkDeviceId: ""
    }
  },

  methods: {
    modalShow(checkId) {
      this.loading = true;
      var _this = this
      this.dialogTableVisible = true
      this.checkDeviceId = checkId
      var params = {
        page: _this.pageData.pageNum,
        size: _this.pageData.pageSize,
        mechanicalId: checkId
      }
      HttpInterface.requestGet(this, HttpInterface.URL_GET_VERIFICATION_RECORD, params, function (res) {
        var data = res.data;
        if (data.success) {
          if (Object.keys(data.other).length > 0) {
            _this.recordList = data.other.verificationRecordDetailsPage.rows;
            _this.pageData.total = data.other.verificationRecordDetailsPage.total;
          } else {
            _this.recordList = [];
            _this.pageData.total = 0;
          }
        } else {
          _this.errorMessage("获取数据失败！");
        }
        _this.loading = false;
      }, function (err) {
        _this.loading = false;
        _this.errorMessage("获取数据失败！");
      })
    },

    pageNumData(page) {
      this.pageData.pageNum = Number(page);
      this.modalShow(this.checkDeviceId);
    },

    pageSizeData(page) {
      this.pageData.pageSize = Number(page);
      this.modalShow(this.checkDeviceId);
    },

    indexMethod(index) {
      return index + 1;
    }
  }
}
</script>

<style scoped>
.import a {
  text-decoration: none;
  color: #4688cc;
}
</style>
